#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

import django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")

'''
Django 版本大于等于1.7的时候，需要加上下面两句
import django
django.setup()
否则会抛出错误 django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
'''
if django.VERSION >= (1, 7):
    django.setup()


def main():
    from restful.contrib.consumer.models import CustomUser as User
    f = open('oldblog.txt')

    for line in f:
        title, content = line.split('****')
        User.objects.get_or_create(title=title,content=content)

    f.close()


if __name__ == "__main__":
    main()
    print('Done!')
